Implementation of Variable Parameter List
When learning C language, do you think that printf is a God-like function like me? He can accept different numbers and different types of parameters. How does he implement it?
Let's take a look at its source
Author: zyl910I. background
Currently, many commonly used UML tools do not support objective-C, which is inconvenient to draw UML. You must manually convert the objective-C syntax parameter list to the UML or C ++ syntax. It is laborious and
First, array initializationAn array is the same type of an object sequence or primitive type data sequence that is encapsulated together with an identifier name. The compiler is not allowed to specify the length of the array, when using the
PHP Extracurricular notes--implementation of variable parameter list of function PHP is very powerful in terms of functions, but for some novice PHP, understanding is part of the difficulty, not fully mastered.In the PHP training tutorial, we
Java variable parameter list
Copy Code code as follows:
Class A {}
Because all classes inherit from object, you can use an object array as a parameter method:
public class parameter {
static void PrintArray
Valid JavaScript Item 21 uses the apply method to call a function to pass in the Variable Parameter List. Valid tiveapply
This series serves as the Reading Notes for objective JavaScript.
The following is a typical example of a method with a
Stdarg macro:mutable parameter lists are implemented by macros that are defined in the stdarg.h header file, which is part of the standard library. This header file declares a type va_list and three macros Va_start,va_arg , and va_end. We can
In a function prototype, the parameters that the function expects to accept are listed, but the function can only display a fixed number of arguments. Is it possible for a function to accept a different number of arguments at different times? The
eg#find/agent4.0/swap/"*" | Xargs-n rm {} \;A procedure that is deleted reports a hint that the file or directory does not exist. But the file was finally removed and the problem solved.
find:0403-027 The parameter list is too long this error
In actual programming, sometimes the function does not know how many parameters need to be passed before it can be determined during program execution. To a certain extent, it also hurts programmers. In fact, in C/C ++, a macro va_arg () that can be
I am very interested in the mutable parameter list recently because it can accept different numbers of parameters. Let's take a look at its statement first:void printf (const char *format,...)We understand it through a concrete example:#include
The C function uses the following macros in the program:void Va_start (va_list arg_ptr, prev_param);type Va_arg (va_list arg_ptr, type);void Va_end (va_list arg_ptr);va_list:a type of information required to hold macro va_start,va_arg , and va_end .
I just want to record the usage of the Variable Parameter List in C. I can't remember it later and have no reference manual at hand. For convenience, I wrote it in C ++, don't blame me.
//// Variable Parameter List Example//# Include # Include #
In C, the following three functions are used to read the value of the variable parameter list.
Va_start (AP, FMT );
Vsprintf (info_buf, FMT, AP );
Va_end (AP );
Use the followingCodeTo demonstrate.
# Include # include #
Self is very useful in distinguishing global variables/functions from member variables/functions in objects. For example, it provides a scope mechanism. I personally think it is much clearer than Ruby's @ and @. This may be a habit, but it is indeed
The PHP function variable argument list can be implemented by the three functions of _get_args (), Func_num_args (), Func_get_arg (). We have described this in more detail below.AD:2014WOT Global Software Technology Summit Beijing Station course
When you want to pass the argument is already a list, the function calls to accept separate parameters, this time can consider the parameter list split:
You can use the * operator to automatically disassemble the parameter list:
args=
//Header filesva_list arg access parameter list not determined partVa_start (Arg,val);/ /Set arg_ptr to the first optional argument passed to the function argument list arg is the variable name declared, Val is the last parameter of the determined
The principle of transfer of function parametersfunction parameters are accessed in memory in the form of stacks, from right to left into the stack.The parameter stores the format in memory:In the process, the stack address is allocated from high to
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.